<template>
	<div class='classList'>
		<div class="classList_tab">
			<u-tabs :list="list1" lineColor="#9013FE" lineWidth="20"
				itemStyle="padding-left: 146rpx; padding-right: 146rpx; height: 44px;" :activeStyle="{
			    color: '#9013FE',
			    fontWeight: 'bold',
			    transform: 'scale(1.05)'
			}" :inactiveStyle="{
			    color: '#999999',
			    transform: 'scale(1)'
			}" @change="changeEvent()"></u-tabs>
		</div>
		<div class="classTop" v-if='status == 0'>
			<hxs :list='classPageList' @upDate='upDate' :pageType='pageType'></hxs>
		</div>

		<div class="classTop" v-if='status == 1'>
			<huanfang :list='classPageList' @upDate='upDate' :pageType='pageType'></huanfang>
		</div>

	</div>
</template>

<style lang="less">
	.classList {
		.classList_tab {
			background: #fff;
			padding: 10rpx 0;
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;

		}

		.classTop {
			margin-top: 120rpx;
		}
	}
</style>


<script>
	import hxs from './com/hxs.vue'
	import huanfang from './com/huanfang.vue'

	export default {
		components: {
			hxs,
			huanfang,
		},
		data() {
			return {
				list1: [{
					name: '回线上',
					status: 0
				}, {
					name: '换房',
					status: 1
				}],
				page: 1,
				status: 0,
				classPageList: [],
				pjshow: false,
				message: '',
				anchor_id: uni.getStorageSync('author_id'),
				pageType: 1,
				isRefresh: false
			}
		},
		onShow() {
			if (this.isRefresh) {
				this.page = 1
				this.classPageList = []
				if (this.pageType == 2) {
					this.getUserClassXZ()
				} else {
					this.getUserClass()
				}
			}
		},
		onLoad(opt) {
			this.pageType = opt.type || 1
			console.log('pageTypepageType', this.pageType)
			if (opt.type == 2) {
				this.getUserClassXZ()
			} else {
				this.getUserClass()
			}
		},
		onReachBottom() {
			// this.page++
			// this.getUserClass()
		},
		methods: {
			changeEvent(item) {
				this.status = item.status
				this.page = 1
				this.classPageList = []
				if (this.pageType == 2) {
					this.getUserClassXZ()
				} else {
					this.getUserClass()
				}
				console.log('changeEventchangeEventchangeEventchangeEvent', this.status);

			},
			async getUserClass() {
				// 0已取消 1报名中 2已完成 3已评价 4已爽约
				if (this.status == 0) {
					const {
						data
					} = await this.$request(this.$Api.noticeList6, {}, "POST")
					if (data.code !== 0) return
					this.classPageList = this.classPageList.concat(data.data)
				} else if (this.status == 1) {
					const {
						data
					} = await this.$request(this.$Api.noticeList7, {}, "POST")
					if (data.code !== 0) return
					this.classPageList = this.classPageList.concat(data.data)
				}
			},
			async getUserClassXZ() {
				// 0已取消 1报名中 2已完成 3已评价 4已爽约
				if (this.status == 0) {
					const {
						data
					} = await this.$request(this.$Api.noticesList2, {}, "POST")
					if (data.code !== 0) return
					this.classPageList = this.classPageList.concat(data.data)
				} else if (this.status == 1) {
					const {
						data
					} = await this.$request(this.$Api.noticesList4, {}, "POST")
					if (data.code !== 0) return
					this.classPageList = this.classPageList.concat(data.data)
				}
			},
			upDate() {
				if (this.pageType == 2) {
					this.getUserClassXZ()
				} else {
					this.getUserClass()
				}
				uni.navigateBack()
			}
		}
	}
</script>